/*
 * Copyright 2013, NuzoweR@Schneefeuer <nuzower@gmail.com>.
 * The Settlers Online - Combat Simulator (tsosim).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef UNITS_H_
#define UNITS_H_

#include <map>
#include <string>

class Unit 
{
public:

	/* **************************************************************************************************** */

	enum Initiative { I_FIRST, I_NORMAL , I_LAST };
	enum Defense    { D_FRONT, D_NORMAL, D_BACK, D_GENERAL };
	enum Skills     { S_NONE = 0, S_ATTACK_WEAKEST = 1, S_SPLASH_DAMAGE = 2, S_TOWER_BONUS = 4, S_GENERAL = 8 };

	static inline int SKILLS(Skills t1)            { return (int)t1; }
	static inline int SKILLS(Skills t1, Skills t2) { return ((int)t1 | (int)t2); }


	/* **************************************************************************************************** */

	Unit ();

	std::string         name_id,
	                    name;
	int                 _name_utf8_length;
	int                 hitpoints;
	int                 min_damage, max_damage;
	unsigned char       accuracy;
	Initiative          initiative;
	int					skills;
	int                 attack_id;

	/* **************************************************************************************************** */

	/*
	 * creates new unit with given name
	 *  - name_id  : string ID, must be unique, must not be a prefix of another unit
	 *  - error    : if an error occurs, e.g. 'name_id' is a prefix, then the error string is written here and NULL is returned
	 */
	static Unit* create(std::string const& name_id, std::string const& name, std::string& error);

	static Unit* get(std::string const& name_id, bool force_name_id=false);

	static const Unit* find(std::string const& name, std::string& error);

	static bool  set_name(std::string const& name_id, std::string const& name, std::string& error);

	static bool  has(std::string const& name_id);
};



#endif // UNITS_H_
